package com.bdqn.jwt1.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.security.core.Authentication;

import java.util.Date;

public class JwtUtil {
    public static String generateToken(Authentication authentication) {
        String token = Jwts.builder()
                .claim("authentication", authentication)
                .setSubject(authentication.getName())
                .setExpiration(new Date(System.currentTimeMillis() + 3600000))
                .signWith(SignatureAlgorithm.HS256, "bdqn")
                .compact();
        return token;
    }

    public static Claims parser(String token) {
        return Jwts.parser().setSigningKey("bdqn").parseClaimsJws(token).getBody();
    }
}
